Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Tempy is a utility package for creating temporary files and directories. It provides a simple API to generate temporary paths, files, and directories that are automatically cleaned up when no longer needed.
Create a temporary file
This feature allows you to create a temporary file. The `tempy.file()` method generates a unique file path in the system's temporary directory.
const tempy = require('tempy');
const tempFilePath = tempy.file();
console.log(tempFilePath);
Create a temporary directory
This feature allows you to create a temporary directory. The `tempy.directory()` method generates a unique directory path in the system's temporary directory.
const tempy = require('tempy');
const tempDirPath = tempy.directory();
console.log(tempDirPath);
Create a temporary file with a specific extension
This feature allows you to create a temporary file with a specific extension. The `tempy.file({ extension: 'txt' })` method generates a unique file path with the specified extension in the system's temporary directory.
const tempy = require('tempy');
const tempFilePath = tempy.file({ extension: 'txt' });
console.log(tempFilePath);
Create a temporary directory with a specific name
This feature allows you to create a temporary directory with a specific name. The `tempy.directory({ name: 'my-temp-dir' })` method generates a unique directory path with the specified name in the system's temporary directory.
const tempy = require('tempy');
const tempDirPath = tempy.directory({ name: 'my-temp-dir' });
console.log(tempDirPath);
The 'tmp' package provides similar functionality for creating temporary files and directories. It offers more control over the lifecycle of temporary files and directories, including the ability to set custom cleanup callbacks.
The 'fs-extra' package extends the native Node.js 'fs' module with additional methods, including methods for creating temporary files and directories. It is a more general-purpose file system utility library compared to tempy.
The 'temp' package is another utility for creating temporary files and directories. It provides a simple API and automatic cleanup, similar to tempy, but with a focus on ease of use and minimal configuration.
Get a random temporary file or directory path
$ npm install tempy
const tempy = require('tempy');
tempy.file();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
tempy.file({extension: 'png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png'
tempy.file({name: 'unicorn.png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png'
tempy.directory();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
Get a temporary file path you can write to.
Type: object
You usually won't need either the extension
or name
option. Specify them only when actually needed.
Type: string
File extension.
Type: string
Filename. Mutually exclusive with the extension
option.
Get a temporary directory path. The directory is created for you.
Write data to a random temp file.
Type: string | Buffer | TypedArray | DataView | stream.Readable
Data to write to the temp file.
See options.
Synchronously write data to a random temp file.
Type: string | Buffer | TypedArray | DataView
Data to write to the temp file.
See options.
Get the root temporary directory path. For example: /private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T
Temp files will be periodically cleaned up on macOS. Most Linux distros will clean up on reboot. If you're generating a lot of temp files, it's recommended to use a complementary module like del
for cleanup.
FAQs
Get a random temporary file or directory path
The npm package tempy receives a total of 8,489,558 weekly downloads. As such, tempy popularity was classified as popular.
We found that tempy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.